package demo1;
class Animal{
    public void eat() {
        System.out.println("正在吃");
    }
}
class Dog extends Animal{
    @Override
    public void eat() {
        System.out.println("吃狗粮");
    }
}
class Cat extends Animal{
    @Override
    public void eat() {
        System.out.println("吃猫粮");
    }
}
class Bird extends Animal{
    @Override
    public void eat() {
        System.out.println("吃鸟食");
    }
}
public class Test {

    public static void main(String[] args) {
        //1  可将向上转型全部定义在数组中
        Animal [] animals = {new Dog(), new Bird(), new Cat()};
        for(Animal a : animals){
            a.eat();
        }
        //2
        Animal animal1 = new Cat();
        Animal animal2 = new Bird();
        Animal animal3 = new Dog();
        Animal [] animal = {animal1, animal2, animal3};
        for(Animal a : animal){
            a.eat();
        }
    }
}
